import dayjs from 'dayjs';

export default function (app) {
    //这样写有问题 下面传来值就给它修改了 热后在使用就一直这样了
    // let formType = "YYYY-MM-DD HH:mm:ss"
    app.directive("transTime", {
        created(el, bindgings) {
            if (bindgings.value) {
                //直接写在bindgings里面
                bindgings.formType = bindgings.value;
            }
        },
        mounted(el, bindgings) {
            const { textContent } = el;
            let time = parseInt(textContent)
            if(textContent.length === 10) {
                time = time * 1000;
            }

            el.textContent = dayjs(time).format(bindgings.formType)
        },
    })
}